package cn.msi.questionnaire.action;

import cn.common.action.GeneralAction;
import cn.msi.questionnaire.domain.Template;
import cn.msi.questionnaire.service.TemplateService;

/**
 * 问卷模板请求Action
 * 
 * @author Administrator
 * 
 */
public class TemplateAction extends GeneralAction {

	private static final long serialVersionUID = 6181609976249829753L;

	private Template template = new Template();
	
	private String indexText;
	
	private String[] questionText;

	private TemplateService templateService;

	/**
	 * 项目问卷模板主页面请求处理方法
	 * 
	 * @return
	 * @throws Exception
	 */
	public String questionnaireIndex() throws Exception {
		return SUCCESS;
	}

	/**
	 * 问卷模板请求处理方法
	 * 
	 * @throws Exception
	 */
	public void searchTemplate() throws Exception {
		page(template);
		String json = templateService.searchTemplate(template);
		out(json);
	}

	/**
	 * 打开模板编辑页面请求处理方法
	 * 
	 * @return
	 * @throws Exception
	 */
	public String openTemplatePage() throws Exception {
		template = templateService.findTemplate(template);
		return SUCCESS;
	}

	/**
	 * 保存项目模板
	 * 
	 * @throws Exception
	 */
	public void editTemplate() throws Exception {
		templateService.editTemplate(template, indexText, questionText);
	}

	/**
	 * 删除问卷模板
	 * 
	 * @throws Exception
	 */
	public void deltetTemplate() throws Exception {
		templateService.deleteTemplate(template);
	}

	/**
	 * 启用问卷模板
	 * 
	 * @throws Exception
	 */
	public void enableTemplate() throws Exception {
		templateService.enableTemplate(template);
	}

	/**
	 * 生成问卷样式
	 * 
	 * @throws Exception
	 */
	public void findContent() throws Exception {
		String html = templateService.findContent(template);
		out(html);
	}

	public void setTemplateService(TemplateService templateService) {
		this.templateService = templateService;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}

	public String getIndexText() {
		return indexText;
	}

	public void setIndexText(String indexText) {
		this.indexText = indexText;
	}

	public String[] getQuestionText() {
		return questionText;
	}

	public void setQuestionText(String[] questionText) {
		this.questionText = questionText;
	}
}
